<?php  if (!defined('PATH_HD')) exit('No direct script access allowed');

class IndexControl extends Control{
    public $template;
    
    function __auto(){
        if (!C("flag")) {
            $this->display(PATH_ROOT.'/static/flag.html');die;
        }
        $template = __ROOT__ . '/template/' . C('tpl_style');
        $this->assign("template", $template);
        $db = M("category");
        $allcat = $db->where("pid=0")->all();
        //当前栏目信息分配到模板
        $this->assign("all",$allcat);
    }

    function index(){
        C("debug",1);
        $db = M("category");
        $catData = $db->where("pid=59")->all();
        //当前栏目信息分配到模板
        $this->assign("indexlist",$catData);
        
        $this->display("index");
    }

        /**
     * 列表页
     */
    function cat() {
         C("debug",1);
        $cid = intval($_GET['cid']);
        if ($cid) {
            $db = M("category");
            $catData = $db->find($cid);
            $arc=m("arc");
            $allData = $arc->where('cid='.$cid)->all();
            //当前栏目信息分配到模板
            $this->assign("field",$catData);
            $this->assign("allData",$allData);
            $this->display($catData['cattpl']);
        } else {
            go(__ROOT__);
        }
    }

    //内容页
    function arc() {
        // p($_SESSION);
        $user=isset($_SESSION['easyuser'])?1:0;
        $aid = @intval($_GET['aid']);
        if ($aid) {
            $com = M("comment");
            $com =$com->where("aid='{$aid}' AND shenhe=1")->all();
            if ($com) {
                foreach ($com as $k => $v) {
                $u=m("user");
                $u=$u->where("userid='{$v['userid']}'")->find();
                $com[$k]['userid']=$u['username'];
            }
            }
            $db = M("arc");
            $field = $db->find($aid);
            $cat = $db->table("category")->find($field['cid']);
            $this->assign("field",$field);
            $this->assign("cat",$cat);
            $this->assign("user",$user);
            $this->assign("com",$com);
            $this->display($cat['arctpl']);
        }
    }

    //内容页
    function addcom() {
            $uname=$_SESSION['easyuser'];
            $db=M("user");
            $user=$db->where("username='{$uname}'")->find();
            $_POST['userid']=$user['userid'];
            $_POST['addtime']=time();
            // p($_POST);die;
            $db = M("comment");
            if ($db->add()) {
                go($_SERVER["HTTP_REFERER"]);
            }else{
                $this->error("提交失败，请重试");
            }
        }











    function ldlist(){
        $this->display("list");
    }
    function ldarc(){
        $this->display("arc");
    }
    function qiyejieshao(){
        $this->display("qiye");
    }
    function chanpin(){
        $this->display("chanpin");
    }
}
?>